package com.reeygu.item.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.reeygu.item.mapper.SeckillGoodsMapper;
import com.reeygu.item.pojo.SeckillGoods;
import com.reeygu.item.service.SeckillGoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author a1304
* @description 针对表【t_seckill_goods】的数据库操作Service实现
* @createDate 2023-08-05 00:21:32
*/
@Slf4j
@Service
public class SeckillGoodsServiceImpl extends ServiceImpl<SeckillGoodsMapper, SeckillGoods>
implements SeckillGoodsService {
    @Autowired
    private SeckillGoodsMapper seckillGoodsMapper;

    @Override
    public int deductSeckillGoods(Long goodsId) {
        Map<String, Object> map = new HashMap<>();
        map.put("goods_id", goodsId);
        List<SeckillGoods> seckillGoodsNum = seckillGoodsMapper.selectByMap(map);
        log.info("成功修改当前秒杀库存{} - 1 = {}", seckillGoodsNum.get(0).getStockCount(), seckillGoodsNum.get(0).getStockCount() - 1);
        return seckillGoodsMapper.updateStockCountByGoodsId(seckillGoodsNum.get(0).getStockCount() - 1, goodsId);
    }
}
